var express = require("express");
var router = express.Router();
var bodyParser = require('body-parser');
router.use(bodyParser.json());

router.get("/", function (req, res, next) {
    res.status(200);
    res.render("index", {
        "title": "CalculatorA",
        "numA": 0.0,
        "numB": 0.0,
        "sum": 0.0,
    });
});

router.post("/back/", function (req, res) {
    console.log("POST: ", req.body.num1, req.body.num2, req.body["num1"]);
    var numA = parseFloat(req.body["num1"]);
    var numB = parseFloat(req.body.num2);
    var sum = numA + numB;
    console.log("sum: " + sum);
    res.status(200);
    res.render("index", {
        "title": "CalculatorB",
        "numA": numA,
        "numB": numB,
        "sum": sum,
    });
});

module.exports = router;